﻿@section Styles{

}
@section Scripts{
    <script type="text/javascript">
        var app = new Vue({
            el: "#app",
            data: function () {
                return {
                    search: {
                        state:false,
                        vm: {
                            Role_Name: null
                        }
                    },
                    table: {
                        columns: [],
                        data: [],
                        page: 1,
                        rows: 15,
                        totalCount: 0,
                        selecteds: []//选中的行
                    },
                    roleId: null,
                    tree: []
                }
            },
            created: function () {
                this.findList();
            },
            mounted: function () {

            },
            methods: {
                //获取列表
                findList: function () {
                    var _this = this;
                    var path = `@Url.Action("FindList")/${_this.table.page}/${_this.table.rows}`;

                    hzyAdmin.post(path, _this.search.vm, function (r) {
                        if (r.status != 1) return;
                        _this.table.data = r.data.DataSource;
                        _this.table.totalCount = r.data.TotalCount;
                        _this.table.columns = r.data.Cols;
                        //选择第一个角色加载他的权限列表
                        if (_this.table.data.length > 0) {
                            _this.roleId = _this.table.data[0]._ukid;
                            _this.getRoleMenuFunctionTree();
                        }

                    });
                },
                //重置
                reset: function () {
                    for (var item in this.search.vm) this.search.vm[item] = null;
                    this.findList();
                },
                //删除
                remove: function (id) {
                    var _this = this;
                    var ids = [];
                    if (id) {
                        ids.push(id);
                    } else {
                        var selecteds = this.table.selecteds;
                        if (selecteds.length == 0) return top.hzyAdmin.alert("请勾选要删除得数据!", "错误");
                        for (var i = 0; i < selecteds.length; i++) {
                            ids.push(selecteds[i]._ukid);
                        }
                    }
                    if (confirm("确定要删除吗?")) {
                        //请求接口删除
                        var path = `@Url.Action("Delete")`;

                        hzyAdmin.post(path, { Ids: ids }, function (r) {
                            top.hzyAdmin.alert("删除成功!", "成功");
                            _this.findList();
                        });
                    }
                },
                openForm: function (id) {
                    var path = `@Url.Action("Info")/${(id ? id : '')}`;
                    var _this = this;

                    hzyAdmin.openPage(id ? '编辑' : '新建', path, function () {
                        _this.findList();//刷新列表
                    });
                },
                getRoleMenuFunctionTree: function () {
                    if (!this.roleId) return hzyAdmin.alert('请选择要设置的角色!','警告');
                    var path = `@Url.Action("RoleMenuFunctionTree")/${(this.roleId ? this.roleId : '')}`;
                    var _this = this;

                    hzyAdmin.post(path, {}, function (r) {
                        if (r.status != 1) return;
                        _this.tree = r.data.list;
                    });
                },
                saveFunctions: function (funs, id) {
                    var path = `@Url.Action("Save")`;
                    var _this = this;

                    hzyAdmin.post(path, {
                        RoleId: this.roleId,
                        MenuId: id,
                        FunctionIds: funs
                    }, function (r) {
                            if (r.status != 1) return;
                            hzyAdmin.alert('设置成功!', '成功');
                    });
                }
            }
        });
    </script>
}
<div class="container-fluid" id="app">
    <el-row :gutter="20">
        <el-col :xs="24" :sm="10" :md="10" :lg="10" :xl="10">

            <div class="card mb-15" v-show="search.state">
                <div class="card-body">
                    <div class="card-title">高级检索</div>
                    <div class="row">
                        <div class="col-sm-8">
                            <div class="row">
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" v-model="search.vm.Function_Name" placeholder="功能名称">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <button type="button" class="btn btn-primary" @@click="findList">检索</button>&nbsp;
                            <button type="button" class="btn btn-secondary" @@click="reset">重置</button>
                        </div>

                    </div>
                </div>
            </div>
            <div class="card m-0">
                <div class="card-body">
                    <div class="row mb-15">
                        <div class="col-sm-12">
                            <button class="btn btn-primary" @@click="search.state=!search.state">高级检索</button>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <el-table :data="table.data"
                                      @@selection-change="(array)=>{table.selecteds=array;}"
                                      row-key="_ukid">
                                @*<el-table-column type="index" width="50" fixed></el-table-column>*@
                                @*<el-table-column type="selection" width="50" fixed></el-table-column>*@
                                <!--根据查询接口自动加载头部信息 start-->
                                <el-table-column v-for="(item,index) in table.columns" :prop="item.DataIndex" :label="item.Title" :key="index" v-if="item.Show"></el-table-column>
                                <!--根据查询接口自动加载头部信息 end-->
                                <el-table-column fixed="right" label="权限" width="100">
                                    <template slot-scope="scope">
                                        <el-link type="primary" @@click="roleId=scope.row._ukid;getRoleMenuFunctionTree();">去设置</el-link>
                                        @*<el-link type="danger" @@click="remove(scope.row._ukid)">删除</el-link>*@
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-pagination @@size-change="(val)=>{table.rows=val;findList();}"
                                           @@current-change="(val)=>{table.page=val;findList();}"
                                           :current-page="table.page"
                                           :page-sizes="[10, 15, 20, 50, 100, 200, 300, 400, 1000]"
                                           :page-size="table.rows"
                                           layout="total, sizes, prev, pager, next, jumper"
                                           :total="table.totalCount"
                                           class="mt-10">
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>

        </el-col>
        <el-col :xs="24" :sm="14" :md="14" :lg="14" :xl="14">

            <div class="card mb-0">
                <div class="card-body">
                    <el-table style="width: 100%;margin-bottom: 20px;"
                              row-key="id"
                              default-expand-all
                              :data="tree"
                              :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                        <el-table-column prop="label" label="菜单名称" width="180"></el-table-column>
                        <el-table-column label="权限">
                            <template slot-scope="scope">
                                <el-checkbox-group v-model="scope.row.checkFunction"
                                                   @@change="item=>saveFunctions(item,scope.row.id)">
                                    <el-checkbox v-for="(item,index) in scope.row.functions"
                                                 :label="item.id"
                                                 :key="index">{{item.label}}</el-checkbox>
                                </el-checkbox-group>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>

        </el-col>
    </el-row>

</div>